

def quicksort(inp)
  ary = inp.dup # making a copy
  return ary if ary.size < 2
  pivot = ary.shift # take first element as a pivot
  quicksort(ary.select {|e| e <= pivot}) + [pivot] + quicksort(ary.select {|e| e > pivot})
end


ar = [4, 3, 4, -1, 0, 5, -1, 0, 2]
p quicksort(ar)
p ar
#p ar.size

